<!-- 课程详情 -->
<template>
  <div>
    <div v-if="contentShow" >
      <course-content :content_id="content_id" :courseInfoId="courseInfoId" @changeContentShow="changeContentShow"></course-content>
    </div>
    <div v-else>
      <page-header @back="goBack" content="课程详情"></page-header>
    <el-row :gutter="10" >
      <el-col :span="18">
        <div class="intro">
          <el-row :gutter="20">
            <el-col :span="6">
              <img :src="courseIntro.cover_picture" />
            </el-col>
            <el-col :span="18">
              <div>
                <div class="item1">{{ courseIntro.course_name}}</div>
                <div class="item2">课程介绍</div>
                <div class="item3">
                 {{ courseIntro.course_intro}}
                </div> 
                 <el-button type="danger" v-if="ifAdd" plain > 已加入</el-button>
                <el-button type="primary" v-else @click="addCourse()">加入学习</el-button>
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="directory">课程目录</div>
        <el-table :data="tableData">
          <el-table-column
            header-align="center"
            width="80"
          >
          <template slot-scope="scope">
            <div>
              课时{{scope.row.order}}：
            </div>
          </template>
          </el-table-column>
          <el-table-column label="标题" prop="title"></el-table-column>
          <el-table-column
            label="课时长"
            prop="time"
            header-align="center"
            align="center"
            width="90"
          ></el-table-column>

          <el-table-column header-align="center" align="center">
            <template  slot-scope="scope">
              <el-button type="primary"  plain @click="startStudy(scope.row.content_id)"> 开始学习 </el-button>
            </template>
          </el-table-column>
          
        </el-table>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div>
            <h3>授课老师</h3>
            <div class="base_info_content">   
                <li> 
                  <div class="base_info_l"> <div>名</div> <div>称</div> </div>
                  <div class="base_info_r">{{ teacherInfo.teacher_name}}</div>
                  </li>
                   <li> 
                  <div class="base_info_l">
                    <div>性</div>
                    <div>别</div>
                  </div>
                  <div class="base_info_r">
                     <div v-if="teacherInfo.gender === 1">男</div>
                      <div v-else>女</div>
                  </div>

                  </li>
                   <li> 
                  <div class="base_info_l">
                    <div>学</div>
                    <div>校</div>
                  </div>
                  <div class="base_info_r">{{teacherInfo.school}}</div>
                  </li>
                   <li> 
                  <div class="base_info_l">教职工号</div>
                  <div class="base_info_r">{{teacherInfo.teacher_number}}</div>
                  </li>
                  <li><div class="base_info_l">
                    <div>简</div>
                    <div>介</div>
                    </div></li>
                  <li>
                    <div class="base_info_intro">{{teacherInfo.intro}}</div>
                  </li>
               
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    </div>
    
  </div>
</template>

<script>
import PageHeader from '../page-header.vue';
import CourseContent from './course-content.vue';

export default {
  components:{PageHeader, CourseContent},
  props:{
    courseInfoId:String
  },
  data() {
    return {
      tableData: [
        {
          order: "1",
          title: "什么是HTML?",
          time: "07.23",
        },
      ],
      ifAdd:false,
      contentShow:false,
      content_id:'',
      teacherInfo:{
        teacher_name:'',
        gender:'',
        school:'',
        teacher_number:'',
        intro:''
      },
      courseIntro:{
        course_name:'',
        course_intro:'',
      },
    };
  },
  created(){
    this.getTeacherData();
    this. getChapterList();
    this. getCourseIntro()
  },
  methods:{
    goBack(){
      this.$emit('changeShowDetail')
    },
    
    //子组件返回当前页面
    changeContentShow(){
        this.contentShow = false;
    },

    //获得章节列表
    getChapterList(){
      this.$http({
        url:this.$http.adornUrl('/stu/explore/chapter'),
        method:'get',
        params:this.$http.adornParams({
          course_info_id:this.courseInfoId
        })
      }).then(({data})=>{
           if(data&&data.code === 0){
             this.tableData = data.data
           }else{
             this.$message(data.msg)
           }
      })
    },
    //开始学习章节内容
    startStudy(content_id){
         this.content_id =content_id;
         this.contentShow = true;
    },

    //获得课程介绍
    getCourseIntro(){
        this.$http({
        url:this.$http.adornUrl('/stu/explore/courseIntro'),
        method:'get',
        params:this.$http.adornParams({
          course_info_id:this.courseInfoId
        })
      }).then(({data})=>{
           if(data&&data.code === 0){
             this.courseIntro = data.data
               if(data.data.ifAddCourse == 1){
                  this.ifAdd = true
               }else{
                 this.ifAdd = false
               }
           }else{
             this.$message(data.msg)
           }
      })
    },

    //加入课程
    addCourse(){
      this.$http({
        url:this.$http.adornUrl('/stu/explore/addCourse'),
        method:'post',
        data:this.$http.adornData({
          course_info_id:this.courseInfoId
        })
      }).then(({data})=>{
        if(data&&data.code === 0){
           this.ifAdd = true
        }else{
          this.$message(data.msg)
        }
      })
    },

    //获得老师信息
    getTeacherData(){
      this.$http({
        url:this.$http.adornUrl('/stu/explore/teacherInfo'),
        method:'get',
        params:this.$http.adornParams({
          course_info_id:this.courseInfoId
        })
      }).then(({data})=>{
           if(data&&data.code === 0){
             this.teacherInfo = data.data
           }else{
             this.$message(data.msg)
           }
      })
    },

    //判断是否加入课程
  
  }
};
</script>

<style  scoped>
.base_info_content{
  height:250px;
}
.base_info_content  li{
  height: 30px;
  line-height: 30px;
  font-size: 14px;
  display: flex;
}
.base_info_l{
  width: 56px;
  display: flex;
   justify-content: space-between;
   color: rgb(102, 102, 109);
   margin-right: 20px;
}
.base_info_r{
   color: rgb(24, 24, 27);
}
.base_info_intro{
  line-height: 20px;
  font-size: 13px;
  color: rgb(88, 84, 84);
  text-indent: 52px;
  letter-spacing: 4px;
}
.chapter {
  background-color: lightgray;
  display: flex;
  line-height: 35px;
  font-size: 15px;
}
.chapter .item1 {
  flex: 6;
  margin-left: 20px;
}
.chapter .item2 {
  flex: 1;
}
.chapter .item3 {
  flex: 1;
  color: rgb(0, 153, 255);
  cursor: pointer;
}
.directory {
  border: 1px solid rgb(68, 131, 6);
  line-height: 30px;
  text-align: center;
  color: rgb(76, 136, 15);
  font-size: 18px;
  margin: 10px 0px;
}
.intro .item1 {
  font-size: 18px;
  line-height: 35px;
  font-weight: bold;
}
.intro .item2 {
  border-left: 4px solid dodgerblue;
  padding-left: 10px;
  font-size: 13px;
  margin-top: 10px;
}
.intro .item3 {
  height: 64px;
  line-height: 16px;
  margin-top: 15px;
  font-size: 13px;
   color: darkgray;
}
.intro img {
   margin-top: 15px;
  height: 140px;
  width: 100%;
}
</style>
